﻿// Copyright (c) Inossem. All rights reserved.
// Licensed under the LGPL-3.0 license. See LICENSE file in the project root for full license information.
using NuGet.Packaging.Core;
using NuGet.Protocol.Core.Types;
using NuGet.Versioning;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DWF.Studio.NuGetManagement
{
    /// <summary>
    /// Nuget包
    /// </summary>
    public class NuGetPackage
    {
        /// <summary>
        /// 包元数据
        /// </summary>
        private IPackageSearchMetadata _packageMetaData = null;

        public NuGetPackage(IPackageSearchMetadata packageMetaData)
        {
            this._packageMetaData = packageMetaData;
        }

        /// <summary>
        /// 包Id
        /// </summary>
        public string Id
        {
            get
            {
                return this._packageMetaData.Identity.Id;
            }
        }

        /// <summary>
        /// 包版本
        /// </summary>
        public string Version
        {
            get
            {
                return this._packageMetaData.Identity.Version.ToFullString();
            }
        }

        /// <summary>
        /// 包抬头
        /// </summary>
        public string Title
        {
            get
            {
                return this._packageMetaData.Title;
            }
        }

        /// <summary>
        /// 图片
        /// </summary>
        public Uri IconUri
        {
            get
            {
                return this._packageMetaData.IconUrl;
            }
        }

        /// <summary>
        /// 包描述
        /// </summary>
        public string Description
        {
            get
            {
                return this._packageMetaData.Description;
            }
        }
        /// <summary>
        /// 包概要
        /// </summary>
        public string Summary
        {
            get
            {
                return this._packageMetaData.Summary;
            }
        }
        /// <summary>
        /// 标签
        /// </summary>
        public string Tags
        {
            get
            {
                return this._packageMetaData.Tags;
            }
        }
        /// <summary>
        /// 作者
        /// </summary>
        public string Authors
        {
            get
            {
                return this._packageMetaData.Authors;
            }
        }

        /// <summary>
        /// 发布时间
        /// </summary>
        public DateTimeOffset? PublishedOn
        {
            get
            {
                return this._packageMetaData.Published;
            }
        }

        /// <summary>
        /// 身份
        /// </summary>
        internal PackageIdentity Identity
        {
            get
            {
                return this._packageMetaData.Identity;
            }
        }

        /// <summary>
        /// 元数据
        /// </summary>
        internal IPackageSearchMetadata PackageSearchMetadata
        {
            get
            {
                return _packageMetaData;
            }
        }

        /// <summary>
        /// 版本信息
        /// </summary>
        /// <returns></returns>
        internal async Task<IEnumerable<VersionInfo>> GetVersionsAsync()
        {
            return await _packageMetaData.GetVersionsAsync();
        }
    }
}
